package com.lingz.manager.modules.wuxue.serviceimpl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.lingz.manager.modules.wuxue.mapper.RealTimeWeatherMapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.lingz.manager.modules.wuxue.entity.RealTimeWeather;
import com.lingz.manager.modules.wuxue.service.RealTimeWeatherService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import com.lingz.manager.common.vo.PageVo;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;

import java.util.Arrays;
import java.util.List;

/**
 * 纽康设备实时气象数据接口实现
 * @author caiyixun
 */
@Slf4j
@Service
@Transactional
public class RealTimeWeatherServiceImpl extends ServiceImpl<RealTimeWeatherMapper, RealTimeWeather> implements RealTimeWeatherService {

    @Autowired
    private RealTimeWeatherMapper realTimeWeatherMapper;

    @Override
    public List<RealTimeWeather> findListRealTimeWeather(RealTimeWeather realTimeWeather){
        LambdaQueryWrapper<RealTimeWeather> wrapper = Wrappers.lambdaQuery(RealTimeWeather.class);
        List<RealTimeWeather> list = realTimeWeatherMapper.selectList(wrapper);
        return list;
    }

    @Override
    public Page<RealTimeWeather> findPageRealTimeWeather(RealTimeWeather realTimeWeather,PageVo pageVo){
        // 当前页数
        int pageNumber = pageVo.getPageNumber();
        // 每页显示的条数
        int pageSize = pageVo.getPageSize();

        LambdaQueryWrapper<RealTimeWeather> wrapper = Wrappers.lambdaQuery(RealTimeWeather.class);
        Page<RealTimeWeather> pageList = realTimeWeatherMapper.selectPage(new Page<>(pageNumber, pageSize),wrapper);
        return pageList;
    }

    @Override
    public String addRealTimeWeather(RealTimeWeather realTimeWeather){
        realTimeWeatherMapper.insert(realTimeWeather);
        return "操作成功";
    }

    @Override
    public String editRealTimeWeather(RealTimeWeather realTimeWeather){
        realTimeWeatherMapper.updateById(realTimeWeather);
        return "操作成功";
    }

    @Override
    public String deleteRealTimeWeather(String[] ids){
        realTimeWeatherMapper.deleteBatchIds(Arrays.asList(ids.clone()));
        return "操作成功";
    }

    @Override
    public RealTimeWeather findRealTimeWeatherById(String id) {
        return baseMapper.selectById(id);
    }
}